﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bilylib;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindSlider();
            BindServiceNews();
            BindNews();
            BindAbout();
            BindText();
        }
    }

    private void BindText()
    {
        DataTable tbTextSlide = new DataTable();
        string sql = "Select TextTitle From TextSlide Where Status = @Status Order By TextID Desc";
        Select select = Select.newInstance();
        select.SetConnectionName("HoangThinhDataConnectionString");
        select.SetValues(1);
        tbTextSlide = select.SelectCustomParam(sql);

        string text = "";

        if (tbTextSlide != null)
        {
            for (int i = 0; i < tbTextSlide.Rows.Count; i++)
            {
                text += tbTextSlide.Rows[i]["TextTitle"].ToString();
                if (i < tbTextSlide.Rows.Count - 1)
                {
                    text += "<a style='width: 20px; height: 5px; margin-left: 900px;'></a>";
                }
            }
        }

        lblTextSlide.Text = text;
    }

    private void BindAbout()
    {
        DataTable tbNews = new DataTable();
        string sql = "Select Top 1 * From Introduction Order By IntroductionID Desc";
        Select select = Select.newInstance();
        select.SetConnectionName("HoangThinhDataConnectionString");
        tbNews = select.SelectQuery(sql);
        rptAbout.DataSource = tbNews;
        rptAbout.DataBind();
    }

    private void BindNews()
    {
        DataTable tbNews = new DataTable();
        string sql = "Select Top 1 * From News Where Status = @Status Order By NewsID Desc";
        Select select = Select.newInstance();
        select.SetConnectionName("HoangThinhDataConnectionString");
        select.SetValues(1);
        tbNews = select.SelectCustomParam(sql);
        rptNews.DataSource = tbNews;
        rptNews.DataBind();
    }

    private void BindServiceNews()
    {
        DataTable tbSvNews = new DataTable();
        string sql = "Select Top 4 * From Service Where CateID = @CateID Order By ServiceID Desc";
        Select select = Select.newInstance();
        select.SetConnectionName("HoangThinhDataConnectionString");
        select.SetValues(1);
        tbSvNews = select.SelectCustomParam(sql);
        dtlServiceNews.DataSource = tbSvNews;
        dtlServiceNews.DataBind();
    }

    private void BindSlider()
    {
        DataTable tbSlide = new DataTable();
        string sql = "Select * From Slider Where Status = @Status Order By SlideID Desc";
        Select select = Select.newInstance();
        select.SetConnectionName("HoangThinhDataConnectionString");
        select.SetValues(1);
        tbSlide = select.SelectCustomParam(sql);
        rptSlider.DataSource = tbSlide;
        rptSlider.DataBind();
    }
}
